package com.usermanage.ServiceImpl;

import com.usermanage.Mapping.*;
import com.usermanage.SecurityConfig.SpringSecurityUtils;
import com.usermanage.SecurityConfig.UserDetail;
import com.usermanage.Service.SecurityService;
import com.usermanage.Service.UserCenterService;
import com.usermanage.Service.UserService;
import com.usermanage.beanParam.*;
import com.usermanage.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * Created by 過客 on 2018/3/9
 */
@Slf4j
@Service("userCenterService")
public class UserCenterServiceImpl implements UserCenterService {

    private static String pageIndex = "1";
    private static String pageSize = "20";

    @Resource
    private UserCenterMapping userCenterMapping;


    @Override
    public Optional getUserDetail(String userId) {
        //1、判断是获取登陆用户信息，还是其他用户信息
        int id = 0;
        if (StringUtils.isBlank(userId)) {
            id = SpringSecurityUtils.getCurrentUser().getId();
        } else {
            id = Integer.valueOf(userId);
        }
        //得到用户详情
        Optional<UserCenterBean> optional = userCenterMapping.findById(id);
        return optional;
    }

    @Override
    public UserCenterBean save(UserCenterBean userCenterBean) throws Exception {
        UserCenterBean result = userCenterMapping.save(userCenterBean);
        return result;
    }

    @Override
    public Optional<UserCenterBean> findById(int id) {
        return userCenterMapping.findById(id);
    }


}
